<!--
 * @Description: 文章详情弹框
 * @Author: Huang Junjie
 * @Date: 2021-04-29 09:36:25
 * @LastEditTime: 2021-04-29 16:28:11
 * @LastEditors: Huang Junjie
-->
<template>
  <div>
    <base-dialog
      v-if="tableData.length !== 0"
      class="home-todo-list-dialog"
      width="90%"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :loading="dialog.loading"
      :disabled="dialog.disabled"
      :show-default-footer="dialog.showDefaultFooter"
      :show-fullscreen="dialog.showFullscreen"
    >
      <div class="todo-list-dialog__title">
        <p class="todo-list-dialog__title-text">{{ tableData[rowIndex].title }}</p>
        <p class="todo-list-dialog__title-time">
          <span class="todo-list-dialog__title-span">发布人：{{ tableData[rowIndex].uploadName }}</span>
          <span class="todo-list-dialog__title-span">文章类型：{{ tableData[rowIndex].itemName }}</span>
          <span class="todo-list-dialog__title-span">发布时间：{{ tableData[rowIndex].createDatetime }}</span>
        </p>
      </div>
      <div class="todo-list-dialog__wrapper">
        <el-scrollbar>
          <div class="todo-list-dialog__text" v-html="tableData[rowIndex].content" />
        </el-scrollbar>
      </div>
      <div v-if="tableData[rowIndex].imagesList.length !== 0" class="file-down">附件下载 <i class="el-icon-download" type="small" /></div>
      <div slot="footer" class="todo-list-dialog__footer">
        <div class="todo-list-dialog__prev">
          <div class="todo-list-dialog__prev-text" title="上一篇文章">
            {{ (rowIndex !== 0) ? tableData[rowIndex - 1].title : '' }}
          </div>
          <el-button
            type="text"
            class="todo-list-dialog__prev-btn"
            :disabled="(rowIndex !== 0) ? false : true"
            @click="clickPrev"
          >上一条</el-button>
        </div>
        <div class="todo-list-dialog__next">
          <el-button
            type="text"
            class="todo-list-dialog__next-btn"
            :disabled="((tableData.length - 1) !== rowIndex) ? false : true"
            @click="clickNext"
          >下一条</el-button>
          <div class="todo-list-dialog__next-text" title="下一篇文章">
            {{ ((tableData.length - 1) !== rowIndex) ? tableData[rowIndex + 1].title : '' }}
          </div>
        </div>
      </div>
    </base-dialog>
  </div>
</template>

<script>
export default {
  props: {
    // 弹框配置
    dialog: {
      type: Object,
      default() {
        return {};
      }
    },

    // 当前行数据的index
    rowIndex: {
      type: Number,
      default() {
        return 0;
      }
    },

    // 数据数组
    tableData: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  methods: {
    // 点击上一条
    clickPrev() {
      this.$emit('clickPrev');
    },

    // 点击下一条
    clickNext() {
      this.$emit('clickNext');
    }
  }
};
</script>

<style lang="scss" scoped>
.home-todo-list-dialog{
  /deep/.el-dialog{
    background: #122854;
    .el-dialog__header{
      background: #122854;
      border-bottom-color: #3585d2;
    }
    .el-dialog__body{
      color: #fff;
      max-height: 90vh;
    }
  }
  .todo-list-dialog__title{
    text-align: center;
    &-text{
      font-size: 28px;
      padding: 0 30px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    &-span {
      margin-right: 20px;
    }
    &-time{
      font-size: 16px;
      margin: 10px 0;
    }
  }
  .todo-list-dialog__wrapper{
    height: calc(90vh - 370px);
    margin: 0 30px;
    border: 1px solid #3585d2;
    border-radius: 9px;
    font-size: 16px;
    line-height: 36px;
    /deep/.el-scrollbar__wrap{
      padding: 20px;
    }
  }
  .file-down {
    cursor: pointer;
    padding: 18px 34px 0;
    font-size: 16px;
    color: #409EFF;
    &:hover {
      color: #ffffff;
      text-decoration-line: underline;
    }
  }
  .todo-list-dialog__footer{
    display: flex;
    .todo-list-dialog__prev{
      flex: 1;
      display: flex;
      align-items: center;
      color: #ffffff;
      &-text{
        flex: 1;
        width: 0;
        text-align: right;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
    .todo-list-dialog__next{
      flex: 1;
      display: flex;
      align-items: center;
      color: #ffffff;
      &-text{
        flex: 1;
        width: 0;
        text-align: left;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>
